<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="订单ID" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="打印人员" prop="printer">-->
<!--        <el-input-->
<!--          v-model="queryParams.printer"-->
<!--          placeholder="请输入打印人员"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

      <el-form-item label="打印人员" prop="printer">
        <el-select v-model="queryParams.printer" placeholder="请选择打印人员" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_cme_printman"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="打印名称" prop="printName">
        <el-input
          v-model="queryParams.printName"
          placeholder="请输入打印名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="打印类型" prop="printItem">-->
<!--        <el-input-->
<!--          v-model="queryParams.printItem"-->
<!--          placeholder="请输入打印类型"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

      <el-form-item label="打印类型" prop="printItem">
        <el-select v-model="queryParams.printItem" placeholder="请选择打印类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_cme_metalPrintitem"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>



      <!--<el-form-item label="打印时长" prop="printrTime">-->
        <!--<el-input-->
          <!--v-model="queryParams.printrTime"-->
          <!--placeholder="检索超过此时长数据"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->

<!--      <el-form-item label="热处理人" prop="heatPreprocessor">-->
<!--        <el-input-->
<!--          v-model="queryParams.heatPreprocessor"-->
<!--          placeholder="请输入热处理人员"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

      <el-form-item label="热处理人" prop="heatPreprocessor">
        <el-select v-model="queryParams.heatPreprocessor" placeholder="请选择热处理人" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_cme_heatman"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备状态" prop="deviceStatus">
        <el-select v-model="queryParams.deviceStatus" placeholder="请选择设备状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_device_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否合格" prop="isqualified">
        <el-select v-model="queryParams.isqualified" placeholder="请选择是否合格" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_quality_result"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="是否处理" prop="isHandl">
        <el-select v-model="queryParams.isHandl" placeholder="请选择是否处理" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_is_handling"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="primary"-->
          <!--plain-->
          <!--icon="el-icon-plus"-->
          <!--size="mini"-->
          <!--@click="handleAdd"-->
          <!--v-hasPermi="['PrintProcess:PrintProcess:add']"-->
        <!--&gt;新增</el-button>-->
      <!--</el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['PrintProcess:PrintProcess:edit']"
        >修改</el-button>
      </el-col>
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="danger"-->
          <!--plain-->
          <!--icon="el-icon-delete"-->
          <!--size="mini"-->
          <!--:disabled="multiple"-->
          <!--@click="handleDelete"-->
          <!--v-hasPermi="['PrintProcess:PrintProcess:remove']"-->
        <!--&gt;删除</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="warning"-->
          <!--plain-->
          <!--icon="el-icon-download"-->
          <!--size="mini"-->
          <!--@click="handleExport"-->
          <!--v-hasPermi="['PrintProcess:PrintProcess:export']"-->
        <!--&gt;导出</el-button>-->
      <!--</el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="PrintProcessList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="打印处理ID" align="center" prop="id" />-->
      <el-table-column label="订单ID" align="center" prop="orderId" />
      <el-table-column label="3D打印人员" align="center" prop="printer">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_cme_printman" :value="scope.row.printer"/>
        </template>
      </el-table-column>
      <el-table-column label="打印名称" align="center" prop="printName" />
<!--      <el-table-column label="打印类型" align="center" prop="printItem" />-->


      <el-table-column label="打印类型" align="center" prop="printItem">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_cme_metalPrintitem" :value="scope.row.printItem"/>
        </template>
      </el-table-column>


      <el-table-column label="打印时长（分钟）" align="center" prop="printrTime" />
<!--      <el-table-column label="热处理人员" align="center" prop="heatPreprocessor" />-->
      <el-table-column label="热处理人员" align="center" prop="heatPreprocessor">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_cme_heatman" :value="scope.row.heatPreprocessor"/>
        </template>
      </el-table-column>
      <el-table-column label="设备状态" align="center" prop="deviceStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_device_status" :value="scope.row.deviceStatus"/>
        </template>
      </el-table-column>
      <!--<el-table-column label="开始时间" align="center" prop="startTime" width="180">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="结束时间" align="center" prop="overTime" width="180">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ parseTime(scope.row.overTime, '{y}-{m}-{d}') }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="质检记录" align="center" prop="qualityRecord" />-->
      <el-table-column label="是否合格" align="center" prop="isqualified">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_quality_result" :value="scope.row.isqualified"/>
        </template>
      </el-table-column>

      <el-table-column label="是否处理" align="center" prop="isHandl">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_is_handling" :value="scope.row.isHandl"/>
        </template>
      </el-table-column>
      <!--<el-table-column label="异常记录" align="center" prop="unnormalRecord" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['PrintProcess:PrintProcess:edit']"
          >修改</el-button>
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-delete"-->
            <!--@click="handleDelete(scope.row)"-->
            <!--v-hasPermi="['PrintProcess:PrintProcess:remove']"-->
          <!--&gt;删除</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="todetail(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改PrintProcess对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="订单ID" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单ID"  :disabled="true"/>
        </el-form-item>
        <el-form-item label="打印人员" prop="printer">
          <el-select v-model="form.printer">
            <el-option
              v-for="dict in dict.type.sys_cme_printman"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="打印名称" prop="printName">
          <el-input v-model="form.printName" placeholder="请输入打印名称" />
        </el-form-item>
<!--        <el-form-item label="打印类型" prop="printItem">-->
<!--          <el-input v-model="form.printItem" placeholder="请输入打印类型" />-->
<!--        </el-form-item>-->

        <el-form-item label="打印类型" prop="printItem">
          <el-select v-model="form.printItem">
            <el-option
              v-for="dict in dict.type.sys_cme_metalPrintitem"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>


        <el-form-item label="打印时长(分钟)" prop="printrTime">
          <el-input v-model="form.printrTime"  :disabled="true"/>
        </el-form-item>
        <el-form-item label="设备状态">
          <el-radio-group v-model="form.deviceStatus">
            <el-radio
              v-for="dict in dict.type.sys_device_status"
              :key="dict.value"
:label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-date-picker clearable size="small"
            v-model="form.startTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="overTime">
          <el-date-picker clearable size="small"
            v-model="form.overTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="质检记录" prop="qualityRecord">
          <el-input v-model="form.qualityRecord" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否合格">
          <el-radio-group v-model="form.isqualified">
            <el-radio
              v-for="dict in dict.type.sys_quality_result"
              :key="dict.value"
:label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
<!--        <el-form-item label="热处理人" prop="heatPreprocessor">-->
<!--          <el-input v-model="form.heatPreprocessor" placeholder="请输入热处理人员" />-->
<!--        </el-form-item>-->

        <el-form-item label="热处理人" prop="heatPreprocessor">
          <el-select v-model="form.heatPreprocessor">
            <el-option
              v-for="dict in dict.type.sys_cme_heatman"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="是否处理">
          <el-radio-group v-model="form.isHandl">
            <el-radio
              v-for="dict in dict.type.sys_is_handling"
              :key="dict.value"
:label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="异常记录" prop="unnormalRecord">
          <el-input v-model="form.unnormalRecord" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPrintProcess, getPrintProcess, delPrintProcess, addPrintProcess, updatePrintProcess } from "@/api/metal/PrintProcess/PrintProcess";

export default {
  name: "PrintProcess",
  dicts: ['sys_device_status', 'sys_quality_result', 'sys_is_handling','sys_cme_printman','sys_cme_heatman','sys_cme_metalPrintitem'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // PrintProcess表格数据
      PrintProcessList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        printer: null,
        orderId: null,
        printName: null,
        printItem: null,
        printrTime: null,
        deviceStatus: null,
        isqualified: null,
        heatPreprocessor: null,
        isHandl: null,
        unnormalRecord: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderId: [
          { required: true, message: "订单ID不能为空", trigger: "blur" }
        ],
        deviceStatus: [
          { required: true, message: "设备状态不能为空", trigger: "blur" }
        ],
        isqualified: [
          { required: true, message: "是否合格不能为空", trigger: "blur" }
        ],
        isHandl: [
          { required: true, message: "是否处理不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    /** 跳转到详情页 */
    todetail(row) {
      const orderid = row.orderId
      this.$router.push({ path: '/CmeMetalDetail', query: {orderid:orderid} })
    },

    /** 查询PrintProcess列表 */
    getList() {
      this.loading = true;
      listPrintProcess(this.queryParams).then(response => {
        this.PrintProcessList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        printer: null,
        orderId: null,
        printName: null,
        printItem: null,
        printrTime: null,
        deviceStatus: 0,
        startTime: null,
        overTime: null,
        qualityRecord: null,
        isqualified: 0,
        heatPreprocessor: null,
        isHandl: 0,
        unnormalRecord: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加打印处理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPrintProcess(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改打印处理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePrintProcess(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPrintProcess(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除PrintProcess编号为"' + ids + '"的数据项？').then(function() {
        return delPrintProcess(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('PrintProcess/PrintProcess/export', {
        ...this.queryParams
      }, `PrintProcess_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
